﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClientTools.Library.Interfaces;

namespace ClientTools.Client.Controls.Versions
{
    public partial class ucVersionsOldStyle : UserControl
    {

        private IVersions _ActVersions;

        public ucVersionsOldStyle()
        {
            InitializeComponent();
        }

        public void SetData(IVersions iVersion)
        {
            _ActVersions = iVersion;
            ClearData();
            Enabled = true;
        }

        public void ClearData()
        {
            this.Label1.Text = "-";
            this.lblMessage1.Text = "";
            this.lblMessage2.Text = "";
            this.pnlContent.Enabled = false;
        }

        private void GetVersions()
        {
            this.ClearData();

            global::ClientTools.Library.DataTypes.Versions.VersionInfo vi;
            try
            {
                vi = this._ActVersions.GetVersionInfos();
            }
            catch (Exception ex)
            {
                this.ClearData();
                this.Enabled = false;
                this.Cursor = Cursors.Default;
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.Label1.Text = "There are " + vi.Documents.ToString() + " documents having " + vi.Versions.ToString() + " versions and " + vi.PropertyData.ToString() + " property data in the database...";
            this.pnlContent.Enabled = true;
        }

        private void tsbGetVersions_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            this.GetVersions();
            this.Cursor = Cursors.Default;
        }

        private void cmdClearVersionsByDate_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            global::ClientTools.Library.DataTypes.Versions.VersionInfo vi;
            try
            {
                ////vi = this._ActVersions.XX_DeleteVersionsByDate(this.DateTimePicker1.Value);
            }
            catch (Exception ex)
            {
                this.ClearData();
                this.Enabled = false;
                this.Cursor = Cursors.Default;
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //this.lblMessage1.Text = "Cleared " + vi.Versions.ToString() + " versions with " + vi.PropertyData.ToString() + " property data and " + vi.Documents.ToString() + " documents!";
            this.GetVersions();

            this.Cursor = Cursors.Default;
        }

        private void cmdClearVersionsByNumberOfItems_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            ////global::ClientTools.Library.Versions.VersionInfo vi;
            try
            {
                ////vi = this._ActVersions.XX_DeleteVersionsByNumberOfItems(Decimal.ToInt32(this.NumericUpDown1.Value));
            }
            catch (Exception ex)
            {
                this.ClearData();
                this.Enabled = false;
                this.Cursor = Cursors.Default;
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ////this.lblMessage2.Text = "Cleared " + vi.Versions.ToString() + " versions with " + vi.PropertyData.ToString() + " property data and " + vi.Documents.ToString() + " documents!";
            this.GetVersions();

            this.Cursor = Cursors.Default;
        }

    }
}
